#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "connection.h"
#include "writedata.h"

#define FILENAME "/tmp/unicorn.rainbows"

int writedata(Connection* connections, short length)
{
	FILE* fp;
	short i;
	time_t currtime;
	
	fp = fopen(FILENAME, "w");
	
	if (fp == NULL)
	{
		fprintf(stderr, "Can't open %s", FILENAME);
		return 1;
	}
	
	for(i = 0; i < length; i++)
	{
		time(&currtime);
		fprintf(fp, "%s %d %d %d", connections[i].client, connections[i].rate,
				currtime - 600, currtime);
	}
	
	fclose(fp);
	
	return 0;
}

int main(){
	Connection * connections = malloc(sizeof(Connection) * 5);
	connections[0].client = "hello";
	connections[0].server = "world";
	connections[0].rate = 50;
	writedata(connections, 1);
	return 0;
}
